<?php
//$_GET['qid']
//$_GET['confirm']有值则表示需要确认
//

	include 'include/function.php';
	
	if(!isset($_user_id))redirect_error(_d('err_need_login'));
	
	if(isset($_GET['qid']))$deletequestion_qid=get_to_mysql($_GET['qid']);
	else redirect('./');
	
	//存在性检测
	$query="select node_id,level,question from question where question_id=$deletequestion_qid ";
	$ret=oj_query($query);
	$row=mysql_fetch_row($ret);
	if(!isset($row[0]))redirect_error(_d('err_no_question'));
	//权限检测
	$deletequestion_id		=$row[0];
	$deletequestion_level	=$row[1];
	$deletequestion_question=$row[2];
	$deletequestion_perm=permission_check_delete($_user_id,$deletequestion_id);
	if(!strstr($deletequestion_perm[0],$deletequestion_level))
		redirect_error("You can't edit the question of $deletequestion_level, because you havn't it.");
	//confirm
	if(!isset($_GET['confirm'])) {
		$query="update node set modify_time=now() where id=$deletequestion_id ";
		$ret=oj_query($query);
		$query="delete from question where question_id=$deletequestion_qid ";
		$ret=oj_query($query);
		redirect('showquestion.php?id=' . $deletequestion_id);
	}
	//待确认
	include 'include/header.php';
	echo "<title>$site_title - Delete Question</title>";
	echo '<center style="font-size:2em;padding-bottom:1em;">';
		echo "Are you sure to delete the question-$deletequestion_qid ?<br>";
		echo "<div class='wapper'>$deletequestion_question</div>";
	echo '</center>';
	echo "<center><a href='deletequestion.php?qid=$deletequestion_qid'>Yes</a>&nbsp;&nbsp;<a href='showquestion.php?id=$deletequestion_id'>Cancel</a></center>";
	
	include 'include/footer.php';
		
?>

